    //function binded with "Login" BUTTON the index.jsp
	function onclick_logSub(){
    	var logNameORemail=$("#logNameORemail").val();
    	var logPassword=$("#logPassword").val();
    	var logUseEmail=($("#selLogInNameType").val()=="Email")?true:false;
    	
    	if((logNameORemail=="")||(logPassword=="")){
    		//alert("PLZ!!!");
    		changeInfor("Please complete your personal information!");
    	}else{
    		//alert(logUseEmail);
    		if(logUseEmail){
    			if(!isEmail(logNameORemail)){
    				//alert("PCYE");
    				changeInfor("Please check your Email address!");
    				return;
    			}
    		}
    		$("#logDivInfor").remove();
    		sendPIToServer(logNameORemail,logPassword,logUseEmail);
    	}
    	//window.location.href="Authorised/WelcomePage.jsp"; 
    }
    
	//function binded with "Reset" BUTTON the index.jsp
    function onclick_logRes(){
    	document.getElementById("logNameORemail").value="";
    	document.getElementById("logPassword").value="";
    }
    
    //to change or initial information displayed
    function changeInfor(infor){
    	if(!document.getElementById("divLogInfo").hasChildNodes()){
    		$("#divLogInfo").append(getHtmlInfor(infor));
    	}else{
    		$("#logDivInfor").remove();
    		$("#divLogInfo").append(getHtmlInfor(infor));
    	}
    }
    
    //to get a string of HTML indicating information in the HTML as a parameter input
    function getHtmlInfor(infor){
    	return "<div style=\"background-color:#000;color:#F00\" align=\"center\" id=\"logDivInfor\" name=\"logDivInfor\">" +
    			"<strong>" +
    			infor +
    			"</strong>" +
    			"</div>";
    }
    
    //to valid if it is a email
    function isEmail(strEmail) {
    	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    function sendPIToServer(usernameORemail,psw,isEmail){
    	//alert("send");
    	var PI={"usernameORemail":usernameORemail,"psw":psw,"isEmail":isEmail};   
    	
    	$.ajax({
    		type: "POST",
            url: "LoginVldt",
            data: PI,
            success: callback,
            dataType: "json"
            });
    }

    function callback(data){
    	if(data.result){
    		window.location.href="Authorised/WelcomePage.jsp"; 
    	}else{
    		changeInfor("User don't exist or password error!");
    	}
    }